package com.ita.dao.impl;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.springframework.stereotype.Repository;

import com.ita.dao.IUserDao;
import com.ita.vo.User;

@Repository(value="userDaoImpl")
public class UserDaoImpl implements IUserDao {

	@PersistenceContext
	private EntityManager em;
	
	
	public EntityManager getEm() {
		return em;
	}

	public void setEm(EntityManager em) {
		this.em = em;
	}

	@Override
	public User query(User user) {
		User u=em.find(User.class, user.getUsername());
		if(u!=null){
			if(u.getPassword().equals(user.getPassword())){
				return u;
			}
			
		}
		em.close();
		return null;
		
	}

	@Override
	public int register(User user) {
		int line=0;
		User u=em.find(User.class, user.getUsername());
		if(u==null){
			em.persist(user);
			line=1;
		}
		else{
			line=0;
		}
		em.close();
		
		return line;

	    
	}

}
